package com.qf.service.impl;

import com.qf.dao.ProjectDao;
import com.qf.dao.StageDao;
import com.qf.pojo.Developer;
import com.qf.pojo.Project;
import com.qf.pojo.Stage;
import com.qf.service.StageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName StageServiceImpl
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/2 21:20
 * @Version 1.0
 **/
@Service("stageService")
public class StageServiceImpl implements StageService {
    @Autowired
    private StageDao stageDao;

    @Autowired

    private ProjectDao projectDao;
    public int addStage(Stage stage) {
        int i = stageDao.addStage(stage);

        return i;
    }

    public List<Stage> findAll() {
        List<Stage> all = stageDao.findAll();
        for (Stage stage : all) {
            int pid = stage.getPid();
            if (pid!=0){
                Project projectById = projectDao.findProjectById(pid);
                if (projectById!=null){
                   stage.setProject(projectById);
                }
            }
        }
        return all;
    }

    public int deleteStage(int pid) {
        int i = stageDao.deleteStage(pid);
        return i;
    }
}
